package com.jn.algorithm.day025.question80;

import java.util.Arrays;

/**
 * @author 江南大学1033190417
 * @date 2022/5/16 14:00
 */
public class Solution {

    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        int cur = nums[0];
        int count = 1;
        int left = 1;
        for (int i = 1; i < n; i++) {
            if (nums[i] == cur && count < 2) {
                count++;
                nums[left++]=cur;
            } else if (nums[i] == cur && count >= 2) {
                continue;
            } else if (nums[i] != cur) {
                cur = nums[i];
                nums[left++]=cur;
                count = 1;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        int[] nums = { 0, 1, 1, 1, 2, 3, 3};
        Solution solution = new Solution();
        System.out.println(solution.removeDuplicates(nums));
        System.out.println(Arrays.toString(nums));
    }
}
